/**
 * 
 */
package cs534.util;

/**
 * @author jhostetler
 *
 */
public final class List
{
	public static double sum( final double[] array )
	{
		double result = 0;
		for( final double t : array ) {
			result += t;
		}
		return result;
	}
	
	public static int sum( final int[] array )
	{
		int result = 0;
		for( final int t : array ) {
			result += t;
		}
		return result;
	}
	
	public static double mean( final double[] ds )
	{
		return sum( ds ) / ds.length;
	}
	
	public static double variance( final double[] ds )
	{
		final double m = mean( ds );
		double v = 0.0;
		for( final double d : ds ) {
			final double diff = d - m;
			v += diff*diff;
		}
		return v / ds.length;
	}
	
	public static int[] range( int first_inclusive, int last_exclusive )
	{
		final int[] result = new int[last_exclusive - first_inclusive];
		int idx = 0;
		for( int i = first_inclusive; i < last_exclusive; ++i ) {
			result[idx++] = i;
		}
		return result;
	}
	
	public static <T> String[] toStringArray( final T[] things )
	{
		final String[] result = new String[things.length];
		for( int i = 0; i < things.length; ++i ) {
			result[i] = things[i].toString();
		}
		return result;
	}
	
	public static String[] toStringArray( final double[] things )
	{
		final String[] result = new String[things.length];
		for( int i = 0; i < things.length; ++i ) {
			result[i] = Double.toString( things[i] );
		}
		return result;
	}
}
